//
//  ZYAppointTowCell.m
//  BestLearning
//
//  Created by Ethan on 2017/9/27.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "ZYAppointTowCell.h"
#import "ZYAppointmentTowModel.h"
@implementation ZYAppointTowCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self setUpSuperView];

    }
    
    
    return self;
    
    
}


- (void)assignByZYAppointmentTowModel:(ZYAppointmentTowModel *)model{
    
    [self.photoIamgeView sd_setImageWithURL:[NSURL URLWithString:[model.u1 valueForKey:@"avatar"] ] placeholderImage:[UIImage imageNamed:@"icon_teacher_default"]];
    
    self.timeLabel.text = [NSString stringWithFormat:@"%@",model.createTime];
    
    
    
    BOOL isUp = [NSString isBlankString:model.teaAdvice];
    
    if (isUp) {
         self.teachDetal.text = @"无";
    }else{
        
        self.teachDetal.text = [NSString stringWithFormat:@"%@",model.teaAdvice];
    }
    
   

    BOOL isUpTow = [NSString isBlankString:model.reply];
    
    if (isUpTow) {
        
        self.chiLabel.text = @"";
        self.submitButton.hidden = NO;
        
    }else{
        self.submitButton.hidden = YES;
        self.chiLabel.text = [NSString stringWithFormat:@"%@",model.reply];
        
    }
    
    
    
    
}



- (void)setUpSuperView{
    
    self.photoIamgeView = [UIImageView new];
    //self.photoIamgeView.image = [UIImage imageNamed:@""];
    self.photoIamgeView.layer.cornerRadius = 25;
    self.photoIamgeView.clipsToBounds = YES;
    [self.contentView addSubview:self.photoIamgeView];

    
    self.timeLabel = [UILabel new];
    self.timeLabel.font = [UIFont systemFontOfSize:13];
    self.timeLabel.textColor = ColorRGB(153,153,153);
    [self.contentView addSubview:self.timeLabel];
    
    
    
    self.teachLabel = [UILabel new];
    self.teachLabel.font = [UIFont systemFontOfSize:15];
    self.teachLabel.textColor = ColorRGB(51, 51, 51);
    [self.contentView addSubview:self.teachLabel];
    
    self.teachDetal = [UILabel new];
    self.teachDetal.font = [UIFont systemFontOfSize:15];
    self.teachDetal.textColor = ColorRGB(102, 102, 102);
    self.teachDetal.numberOfLines = 0;
    [self.contentView addSubview:self.teachDetal];
    
    self.chiLabel = [UILabel new];
    //    self.chiLabel.backgroundColor = [UIColor purpleColor];
    self.chiLabel.numberOfLines = 0;
    self.chiLabel.font = [UIFont systemFontOfSize:15];
    self.chiLabel.backgroundColor = ColorRGB(247, 245, 245);
    self.chiLabel.textColor = ColorRGB(102, 102, 102);
    [self.contentView addSubview:self.chiLabel];


    
    self.submitButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
    [self.submitButton setImage:[UIImage imageNamed:@"icon_commend_default"] forState:(UIControlStateNormal)];
    [self.submitButton addTarget:self action:@selector(submitButtonAction:) forControlEvents:(UIControlEventTouchUpInside)];
    self.submitButton.hidden = YES;
    self.submitButton.layer.cornerRadius = 5;
    self.submitButton.clipsToBounds = YES;
    [self.contentView addSubview:self.submitButton];
    
    
    [self.photoIamgeView  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(8);
        make.top.offset(8);
        make.width.height.offset(50);
    }];
    
    self.timeLabel.text = @"2012-2-22";
    [self.timeLabel  mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-8);
        make.centerY.equalTo(self.photoIamgeView);
    }];
    
    
    
    self.teachLabel.text = @"老师建议：";
    [self.teachLabel mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.equalTo(self.photoIamgeView.mas_right).offset(3);
        make.centerY.equalTo(self.photoIamgeView);
        
    }];
    
    self.teachDetal.text = @"舍利子, 是诸法空相, 不生不灭, 不垢不净, 不增不减";
    [self.teachDetal mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(15);
        make.top.equalTo(self.photoIamgeView.mas_bottom).offset(8);
        make.right.equalTo(self).offset(-15);
    }];
    
    self.chiLabel.text = @"家长和孩子意见：";
    [self.chiLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.photoIamgeView);
        make.top.equalTo(self.teachDetal.mas_bottom).offset(8);
    }];
    
    
    
    [self.submitButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-8);
        make.top.equalTo(self.teachDetal.mas_bottom).offset(8);
    }];
    
    
   
        
    UILabel *grayOne = [UILabel new];
    grayOne.backgroundColor = ColorRGB(247, 245, 245);
    [self.contentView addSubview:grayOne];
    
    [grayOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(0);
        make.top.equalTo(self.submitButton.mas_bottom).offset(5);
        make.width.offset(kScreenWidth);
        make.height.offset(1);
    }];
        
        
        [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.offset(0);
            make.bottom.mas_equalTo(grayOne).offset(8);
        }];
        
        
   
        
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
}


- (void)submitButtonAction:(UIButton *)sender{
    
  
    if ([_delegate respondsToSelector:@selector(tableViewCell:commentses:)]) {
        [_delegate tableViewCell:self commentses:sender];
    }
    
    
    
}










@end
